import smtplib
import os

def sendMail(pname, receivers, jobid, url):
    initials = pname.split("@")[0]
    sender = 'jake.lin@uni.lu'
    #receivers.append("christian.jaeger@uni.lu")
    message = """From: IDARE Metanode Server <thomas.pfau@uni.lu>
To: User
Subject: %s

%s
    """ %(jobid + "_" + initials, "Hello " + pname + ",\n\nGCMSJob results are posted. Use link below to access result files and cost summary.\n" + url + "\n\nCheers and feel free to contact Christian/Jake with questions")

    try:
        smtpObj = smtplib.SMTP('localhost')
        smtpObj.sendmail(sender, receivers, message)
    except SMTPException:
        print "Error: unable to send email"


os.system('touch /var/www/metanodeui/data/_100.out')
sendMail("Jake Lin", ["jlin212@gmail.com", "jake.lin@student.tut.fi"], "Completed results: 100", "http://metabolomics.uni.lux/gcms_platform/index.html?jobkey=" + "_100")
